<template>
  <div class="changePassword">
    <!-- 修改登录密码 -->
    <div class="new_vs">
      <div class="vs-top">
        <p>修改登录密码</p>
        <!-- <i class="el-icon-close"></i> -->
      </div>
      <div class="msg">
        <p>操作员</p>
        <el-input v-model="input1" disabled></el-input>
        <p>原密码</p>
        <el-input clearable ref="inp2" v-model="input2" placeholder="请输入原密码" type="password"></el-input>
        <p>新密码</p>
        <el-input clearable ref="inp3" v-model="input3" placeholder="请输入新密码" type="password"></el-input>
        <p>确认密码</p>
        <el-input clearable v-model="input4" placeholder="请再确认密码" type="password" @keyup.enter.native="determine"></el-input>
      </div>
      <div class="vs-btn">
        <!-- <el-button>取消</el-button> -->
        <el-button @click="determine" type="primary">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { modifyPassword } from '../../../network/login'

import enterUp from '../../../components/mixins/enterUp'

export default {
  mixins: [enterUp],
  data(){
    return {
      input1: document.cookie.match(RegExp('jxUser'+'=([^;]+)'))[1],
      input2: '',
      input3: '',
      input4: '',
    }
  },
  methods: {
    determine(){
      if (!this.input2) {
        this.$alert('原密码不能为空', '', {
          confirmButtonText: '确定'
        }).then(
          this.$refs.inp2.focus()
        )
        return
      }
      if (this.input3.length < 6) {
        this.$alert('密码最少为6位', '', {
          confirmButtonText: '确定'
        }).then(
          this.$refs.inp3.focus()
        )
        return
      }
      if (this.input3 != this.input4) {
        this.$alert('新密码与确认密码不一致', '', {
          confirmButtonText: '确定'
        })
        return
      }
      modifyPassword({
        oldPassword: this.input2,
        newPassWord: this.input3
      }).then(res => {
        if (res.data.code == 200) {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
        } else {
          this.$message.error('修改失败')
        }
      })
    }
  }
}
</script>

<style scoped>
  .changePassword{
    margin-right: 0.5vw;
    padding: 0 15px;
    background-color: white;
    height: 95vh;
    position: relative;
  }
  .new_vs{
    position: fixed;
    top: 25%;
    left: 50%;
    transform: translateX(-50%);
    width: 270px;
    padding-bottom: 10px;
    z-index: 99;
    background-color: white;
    box-shadow: 0 0 5px #aaaaaa;
  }
  .new_vs .vs-top{
    height: 40px;
    background-color: #f8f8f8;
  }
  .new_vs .vs-top p{
    font-weight: 700;
    float: left;
    line-height: 40px;
    padding-left: 20px;
  }
  .new_vs .vs-top i{
    float: right;
    line-height: 40px;
    padding: 0 16px;
  }
  .msg {
    padding: 10px;
    margin-bottom: 10px;
  }
  .msg p{
    display: inline-block;
    width: 75px;
    text-align: right;
    margin-right: 10px;
    line-height: 40px;
  }
  .vs-btn{
    margin-left: 195px;
  }
</style>

<style>
  .changePassword .el-input__icon {
    line-height: 10px;
  }
  .changePassword .el-input{
    display: inline;
  }
  .changePassword .el-input__inner{
    height: 30px;
    width: 160px;
  }
</style>